import SimpleITK as sitk
import os

save_path = r'E:\HFUT\BME\BME_competition\Deep_Learning_Models\Swin-Unet-main\test_all_pic\predictions\s97'

file_list = os.listdir(save_path)
file_list.sort()
file_names = [os.path.join(save_path, f) for f in file_list]

newspacing = [1, 1, 1]  # 设置x，y, z方向的空间间隔
reader = sitk.ImageSeriesReader()
reader.SetFileNames(file_names)
vol = reader.Execute()
vol.SetSpacing(newspacing)
sitk.WriteImage(vol, 's097.nii.gz')  # 保存为.nii也 可
